<%@include file="/WEB-INF/student_header.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>驾校学员信息系统</title>
<style type="text/css">
#list li {
	font-size: large;
	font-family: sans-serif;
}

.container {
	width: 75%
}
</style>
</head>
<body>
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">个人中心</h1>
			</div>
		</div>
		<div class="container">
			<div class="jumbotron">
				<h2>${stu.name }</h2>
				<hr class="my-4">
				<ul id="list">
					<li>身份证号：${stu.IDcard }</li>
					<li>年龄：${stu.age eq null?'未知':stu.age}</li>
					<li>联系方式：${stu.telephone eq null?'暂无':stu.telephone}</li>
					<li>地址：${stu.address eq null?'暂无':stu.address }</li>
					<li>科目一成绩：${stu.subject_1 eq null?'暂未考试':stu.subject_1}</li>
					<li>科目二成绩：${stu.subject_2 eq null?'暂未考试':stu.subject_2}</li>
					<li>科目三成绩：${stu.subject_3 eq null?'暂未考试':stu.subject_3}</li>
					<li>科目四成绩：${stu.subject_4 eq null?'暂未考试':stu.subject_4}</li>
					<li>学员状态：${stu.status }</li>
					<li>训练编号：${stu.train_id }</li>
				</ul>
				<div style="margin-left: 15px">
					<a><button type="button" class="btn btn-primary"
							data-toggle="modal" data-target="#stuEditDialog"
							onclick="editStu()">编辑个人资料</button></a>
				</div>
			</div>
		</div>
	</div>

	<!-- 修改用户信息模态框 -->
	<div class="modal fade" id="stuEditDialog" data-backdrop="static"
		tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改个人信息</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="edit_student_form">
					<p style="color: red; width: 100%; text-align: center" id="message">${msg}</p>
						<input type="hidden" id="edit_stu_id" name="id" readonly />
						<div class="form-group" id="form_student">
							<label for="edit_stuName" style="float: left; padding: 7px 15px 0 27px; margin-right: 14px">用户名</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_stuName"
									placeholder="用户名称" name="user_name" required />
							</div>
						</div>
						<div class="form-group" id="form_user">
							<label for="edit_stuPass"
								style="float: left; padding: 7px 15px 0 27px; margin-right: 28px">密码</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_stuPass"
									name="password" required />
							</div>
						</div>
						<div class="form-group" id="form_user">
							<label for="edit_stutelephone"
								style="float: left; padding: 7px 15px 0 27px;">联系方式</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_stutelephone"
									placeholder="暂无联系方式" name="telephone" />
							</div>
						</div>
						<div class="form-group" id="form_user">
							<label for="edit_stuAge"
								style="float: left; padding: 7px 15px 0 27px; margin-right: 28px">年龄</label>
							<div class="col-sm-10">
								<input type=number class="form-control" id="edit_stuAge"
									name="age" max=100 min=0 value=1 step=1 placeholder="未知" />
							</div>
						</div>
						<div class="form-group" id="form_user">
							<label for="edit_stuAddress"
								style="float: left; padding: 7px 15px 0 27px; margin-right: 28px">地址</label>
							<div class="col-sm-10">
								<input type=text class="form-control" id="edit_stuAddress"
									name="address"  placeholder="未知" />
							</div>
						</div>
						
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="updateStu()">修改</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
//获取修改的个人信息
function editStu() {
	  $.ajax({
	        type:"get",
	        url:"<%=basePath%>student/getStuinfo.action",
			data : {},
			success : function(data) {
				$("#edit_stu_id").val(data.id);
				$("#edit_stuName").val(data.user_name);
				$("#edit_stuPass").val(data.password);
				$("#edit_stuAge").val(data.age);
				$("#edit_stutelephone").val(data.telephone);
				$("#edit_stuAddress").val(data.address);
			}
		});
	}
	// 执行修改用户操作
	function updateStu() {
		var user_name = $("#edit_stuName").val();
		var password = $("#edit_stuPass").val();
		if(user_name == null || password == null || user_name=="" || password==""){
			$("#message").text("用户名或密码不能为空！");
			return false
		}
		$.post("${pageContext.request.contextPath}/student/updateStu.action", $(
				"#edit_student_form").serialize(), function(data) {
			if (data == "OK") {
				alert("信息修改成功！");
				window.location.reload();
			} else {
				alert("信息修改失败！");
				window.location.reload();
			}
		});
	}
</script>
</html>
<%@include file="/WEB-INF/footer.jsp"%>